package com.geping.etl.common.controller;

import com.geping.etl.common.entity.Sys_Subject;
import com.geping.etl.common.service.Sys_SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class Sys_SubjectController {

    @Autowired
    private Sys_SubjectService ssr;

    // 系统下拉框
    @RequestMapping(value="/getNameId",method= RequestMethod.POST)
    public List<Map<String,Object>> getNameId(HttpServletResponse response){


        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8"); //响应编码
        // System.out.println("jsp页面加载即触发");

        List<Sys_Subject> namelist = ssr.findAllIdName();
        System.out.println("查询到的类别："+namelist);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (Sys_Subject s : namelist) {
            Map<String, Object> map = new HashMap<String, Object>();
            //只取subName、subId即可。
            String subName = s.getSubjectName().toString();
            String subId = s.getId().toString();
            //map存放键值对
            map.put("subName",subName);
            map.put("subId",subId);
            //list存放map
            list.add(map);
            System.out.println("json格式:"+list); //打印出来就成为了json格式
        }
        return list;
    }

    // 系统下拉框
    @RequestMapping(value="/getSystemName",method= RequestMethod.POST)
    public List<Map<String,Object>> getSystemName(HttpServletResponse response){

        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8"); //响应编码

        List<Sys_Subject> namelist = ssr.findAllIdName();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("subText", "请选择");
        m.put("subValue","");
        list.add(m);
        for (Sys_Subject s : namelist) {
            Map<String, Object> map = new HashMap<String, Object>();
            //只取subName、subId即可。
            String subName = s.getSubjectName().toString();
            //map存放键值对
            map.put("subText",subName);
            map.put("subValue",subName);
            //list存放map
            list.add(map);
        }
        return list;
    }

}
